﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RayTracing
{
    public partial class CameraControls : Form
    {
        public CameraControls()
        {
            InitializeComponent();
            camXText.Text = "0";
            camYText.Text = "0";
            camZText.Text = "-5";
            maxBox.Text = "20";
            minBox.Text = "-20";

        }
        
                //Camera Y Controls
        private void camYScroll_ValueChanged(object sender, EventArgs e)
        {
            if (Main.sceneSelected)
            {
                Main.camera.pos.z = (float)camYScroll.Value / 10;
                camYText.Text = "" + (float)camYScroll.Value / 10;
                Main.cameraMoved = true;
            }
        }

                //Camera X Controls
        private void camXScroll_ValueChanged(object sender, EventArgs e)
        {
            if (Main.sceneSelected)
            {
                Main.camera.pos.x = (float)camXScroll.Value / 10;
                camXText.Text = "" + (float)camXScroll.Value / 10;
                Main.cameraMoved = true;
            }
        }

                //Camera Z Controls
        private void camZScroll_ValueChanged(object sender, EventArgs e)
        {
            if (Main.sceneSelected)
            {
                Main.camera.pos.y = camZScroll.Value;
                camZText.Text = "" + Main.camera.pos.y;     
                Main.cameraMoved = true;
            }
        }

                //Camera Headings Controls
        private void headingText_TextChanged(object sender, EventArgs e)
        {
            if (Main.sceneSelected)
            {
                int temp = 0;
                try
                {
                    temp = int.Parse(headingText.Text);
                }
                catch (Exception ex)
                {
                    temp = 0;
                    headingText.Text = "0";
                }
                headingScroll.Value = temp;
                Main.camera.hpr.x = temp;
                Main.cameraMoved = true;
            }
        }
        private void headingScroll_ValueChanged(object sender, EventArgs e)
        {
            if (Main.sceneSelected)
            {
                headingText.Text = "" + headingScroll.Value;
                Main.camera.hpr.x = headingScroll.Value;
                Main.cameraMoved = true;
            }
        }


                //Camera Pitch Controls
        private void pitchText_TextChanged(object sender, EventArgs e)
        {
            if (Main.sceneSelected)
            {
                int temp = 0;
                try
                {
                    temp = int.Parse(pitchText.Text);
                }
                catch (Exception ex)
                {
                    temp = 0;
                    pitchText.Text = "0";
                }
                pitchScroll.Value = temp;
                Main.camera.hpr.y = temp;
                Main.cameraMoved = true;
            }
        }
        private void pitchScroll_ValueChanged(object sender, EventArgs e)
        {
            if (Main.sceneSelected)
            {
                pitchText.Text = "" + pitchScroll.Value;
                Main.camera.hpr.y = pitchScroll.Value;
                Main.cameraMoved = true;
            }
        }


               //Camera Roll Controls
        private void rollText_TextChanged(object sender, EventArgs e)
        {
            if (Main.sceneSelected)
            {
                int temp = 0;
                try
                {
                    temp = int.Parse(rollText.Text);
                }
                catch (Exception ex)
                {
                    temp = 0;
                    rollText.Text = "0";
                }
                rollScroll.Value = temp;
                Main.camera.hpr.z = temp;
                Main.cameraMoved = true;
            }
        }
        private void rollScroll_ValueChanged(object sender, EventArgs e)
        {
            if (Main.sceneSelected)
            {
                rollText.Text = "" + rollScroll.Value;
                Main.camera.hpr.z = rollScroll.Value;
                Main.cameraMoved = true;
            }
        }

        private void camSetXY_Click(object sender, EventArgs e)
        {
            int min;
            int max;
            try
            {
                min = int.Parse(minBox.Text);
                max = int.Parse(maxBox.Text);
            }
            catch (Exception ex)
            {
                min = 0; max = 0;
                minBox.Text = "0";
                maxBox.Text = "0";
            }
            camXScroll.Maximum = max;
            camXScroll.Minimum = min;
            camYScroll.Maximum = max;
            camYScroll.Minimum = min;
        }

        private void camXYDefault_Click(object sender, EventArgs e)
        {
            camXScroll.Maximum = 20;
            camXScroll.Minimum = -20;
            camYScroll.Maximum = 20;
            camYScroll.Minimum = -20;
        }   
    }
}
